package cn.wokoba.service.task.repository;


import cn.wokoba.dao.mapper.TaskMapper;
import cn.wokoba.dao.pojo.Task;
import cn.wokoba.service.task.model.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TaskRepository {
    @Autowired
    TaskMapper taskMapper;



    public List<TaskEntity> queryNoSendMessageTaskList() {
        List<Task> tasks = taskMapper.queryNoSendMessageTaskList();
        return  tasks.stream().map(task -> {
            TaskEntity taskEntity = new TaskEntity();
            taskEntity.setUserId(task.getUserId());
            taskEntity.setTopic(task.getTopic());
            taskEntity.setMessageId(task.getMessageId());
            taskEntity.setMessage(task.getMessage());
            return taskEntity;
        }).toList();
    }

    public void updateTaskSendMessageCompleted(String userId, String messageId) {
        Task taskReq = new Task();
        taskReq.setUserId(userId);
        taskReq.setMessageId(messageId);
        taskMapper.updateTaskSendMessageCompleted(taskReq);
    }

    public void updateTaskSendMessageFail(String userId, String messageId) {
        Task taskReq = new Task();
        taskReq.setUserId(userId);
        taskReq.setMessageId(messageId);
        taskMapper.updateTaskSendMessageFail(taskReq);
    }
}
